import axios from "axios";
import { timeStampTurnTime } from "../newsUtil/TimeStampTurnTime";

//金融新闻
export function findData(params) {
  return axios
    .get("/api/news")
    .then(response => {
      let res = response.data;
      for (let i = 0; i < res.length; i++) {
        res[i].updated_at = timeStampTurnTime(res[i].updated_at);
      }
      return res;
    })
    .catch(function() {
      return 0;
      console.log(" findData-API:error");
    });
}

//微博热点
export function findWeiboHot(params) {
  return axios
    .get("/api/Weibo")
    .then(response => {
      let res = response.data;
      for (let i = 0; i < res.length; i++) {
        if (res[i].hotValue.search("热度") == -1) {
          res[i].hotValue = res[i].hotValue + " 热度";
        }
      }
      return res;
    })
    .catch(function() {
      return 0;
      console.log("findWeiboHot-API:error");
    });
}

//汇率查询
export function findExchangeRate(params) {
  return axios
    .get("/api/exchangeRate")
    .then(response => {
      let res = response.data;
      return res;
    })
    .catch(function() {
      return 0;
      console.log("findExchangeRate-API:error");
    });
}
